<template>
  <!-- 深空背景 -->
  <div class="space-background">
    <!-- 流星 -->
    <div class="meteor meteor-1">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-2">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-3">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-4">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-5">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-6">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-7">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-8">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-9">
      <div class="meteor-trail"></div>
    </div>
    <div class="meteor meteor-10">
      <div class="meteor-trail"></div>
    </div>
    
    <!-- 星星 -->
    <div class="stars">
      <div class="star" v-for="n in 300" :key="n" :style="getStarStyle(n)"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// 生成星星样式
const getStarStyle = (index: number) => {
  const size = Math.random() * 2 + 1
  const opacity = Math.random() * 0.7 + 0.3
  const x = Math.random() * 100
  const y = Math.random() * 100
  const duration = Math.random() * 3 + 2
  const delay = Math.random() * 5
  
  return {
    width: `${size}px`,
    height: `${size}px`,
    opacity: opacity,
    left: `${x}%`,
    top: `${y}%`,
    animationDuration: `${duration}s`,
    animationDelay: `${delay}s`
  }
}
</script>

<style scoped>
/* 深空背景 */
.space-background {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  background: linear-gradient(45deg, #0a0a2a, #1a1a4a, #0a0a2a) !important;
  z-index: 1 !important;
  overflow: hidden !important;
  transform: none !important;
  transition: none !important;
  animation: none !important;
}

/* 星星 */
.stars {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.star {
  position: absolute;
  background: #ffffff;
  border-radius: 50%;
  animation: twinkle infinite ease-in-out;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* 流星 */
.meteor {
  position: absolute;
  width: 3px;
  height: 3px;
  background: linear-gradient(45deg, #ffffff, #4fc3f7, #29b6f6);
  border-radius: 50%;
  box-shadow: 0 0 8px 3px #4fc3f7, 0 0 12px 6px rgba(79, 195, 247, 0.5);
  opacity: 0;
  z-index: 2;
}

/* 流星拖尾效果 */
.meteor-trail {
  position: absolute;
  width: 80px;
  height: 1px;
  background: linear-gradient(to right bottom, transparent, rgba(41, 182, 246, 0.4), rgba(79, 195, 247, 0.8));
  top: -30px; /* 向下移动20px */
  right: -8px; /* 继续向右移动 */
  transform: translateY(0) rotate(45deg); /* 重置transform的垂直平移 */
  opacity: 1; /* 保持完全不透明 */
  filter: blur(1px);
}

.meteor-1 {
  animation: meteor-fall 6s infinite linear;
  top: -20px;
  left: 5%;
}

.meteor-2 {
  animation: meteor-fall 8s infinite linear;
  animation-delay: 1s;
  top: -20px;
  left: 15%;
}

.meteor-3 {
  animation: meteor-fall 7s infinite linear;
  animation-delay: 2s;
  top: -20px;
  left: 25%;
}

.meteor-4 {
  animation: meteor-fall 10s infinite linear;
  animation-delay: 3s;
  top: -20px;
  left: 35%;
}

.meteor-5 {
  animation: meteor-fall 9s infinite linear;
  animation-delay: 4s;
  top: -20px;
  left: 45%;
}

.meteor-6 {
  animation: meteor-fall 11s infinite linear;
  animation-delay: 5s;
  top: -20px;
  left: 55%;
}

.meteor-7 {
  animation: meteor-fall 8s infinite linear;
  animation-delay: 6s;
  top: -20px;
  left: 65%;
}

.meteor-8 {
  animation: meteor-fall 12s infinite linear;
  animation-delay: 7s;
  top: -20px;
  left: 75%;
}

.meteor-9 {
  animation: meteor-fall 7s infinite linear;
  animation-delay: 8s;
  top: -20px;
  left: 85%;
}

.meteor-10 {
  animation: meteor-fall 9s infinite linear;
  animation-delay: 9s;
  top: -20px;
  left: 95%;
}

@keyframes meteor-fall {
  0% {
    opacity: 0;
    transform: translateY(0) translateX(0);
  }
  5% {
    opacity: 1;
  }
  80% {
    opacity: 1;
    transform: translateY(100vh) translateX(400px); /* 屏幕底部边缘 */
  }
  100% {
    opacity: 0;
    transform: translateY(calc(100vh + 400px)) translateX(800px); /* 按照原有方向继续飞行 */
  }
}

@keyframes trail-fade {
  0% {
    opacity: 0;
    transform: translateY(0) rotate(45deg) scaleX(0.2);
  }
  20% {
    opacity: 0.7;
    transform: translateY(0) rotate(45deg) scaleX(0.8);
  }
  40% {
    opacity: 0.4;
    transform: translateY(0) rotate(45deg) scaleX(1);
  }
  60% {
    opacity: 0.6;
    transform: translateY(0) rotate(45deg) scaleX(0.9);
  }
  80% {
    opacity: 0.3;
    transform: translateY(0) rotate(45deg) scaleX(0.6);
  }
  100% {
    opacity: 0;
    transform: translateY(0) rotate(45deg) scaleX(0.2);
  }
}
</style>